-
An
MGLStyleobject represents the active map style of anMGLMapView. A style defines both the map’s content and every aspect of its appearance. Styles can be designed in Mapbox Studio and hosted on mapbox.com.MGLStyleprovides methods for inspecting and manipulating a style dynamically, with classes and properties that parallel the style JSON format defined by the Mapbox Style Specification.You set a map view’s active style using the
MGLMapView.styleURLproperty.MGLStyleprovides a set of convenience methods that return the URLs of popular Mapbox-designed styles. Once the-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]or-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]method is called, signaling that the style has finished loading, you can use theMGLMapView.styleproperty to obtain the map view’sMGLStyle.A style primarily consists of the following components:
- Content sources supply content to be shown on the map. Use methods such as
-sourceWithIdentifier:and-addSource:to configure the style’s content sources, which are represented byMGLSourceobjects. - Style layers manage the layout and appearance of content at specific
z-indices in the style. Most kinds of style layers display content provided
by a content source. Use methods such as
-layerWithIdentifier:and-addLayer:to configure the style’s layers, which are represented byMGLStyleLayerobjects. - Style images are used as icons and patterns in style layers. Use the
-setImage:forName:method to register an image as a style image. (Annotations are represented by annotation images rather than style images. To configure an annotation’s appearance, use the-[MGLMapViewDelegate mapView:imageForAnnotation:]method.) - The style’s light is the light source affecting any 3D extruded fills.
Use the
lightproperty to configure the style’s light, which is represented by anMGLLightobject.
The
MGLStyle,MGLSource,MGLStyleLayer, andMGLLightclasses are collectively known as the runtime styling API. The active style influences a related API, visible feature querying, which is available through methods such as-[MGLMapView visibleFeaturesInRect:].Some terminology differs between the Mapbox Style Specification and the various classes associated with
MGLStyle. Consult the “Information for Style Authors” guide for an overview of these differences.See moreNote
Wait until the map style has finished loading before modifying a map’s style via any of theMGLStyleinstance methods below. You can use the-[MGLMapViewDelegate mapView:didFinishLoadingStyle:]or-[MGLMapViewDelegate mapViewDidFinishLoadingMap:]methods as indicators that it’s safe to modify the map’s style.Declaration
Objective-C
@interface MGLStyle : NSObjectSwift
class MGLStyle : NSObject - Content sources supply content to be shown on the map. Use methods such as
-
An
MGLStyleValueobject is a generic container for a style attribute value. The layout and paint attribute properties ofMGLStyleLayercan be set toMGLStyleValueobjects.The
MGLStyleValueclass itself represents a class cluster. Under the hood, a particularMGLStyleValueobject may be either anMGLConstantStyleValueto represent a constant value or one of the concrete subclasses ofMGLStyleFunctionto represent a value function. Do not initialize anMGLStyleValueobject directly; instead, use one of the class factory methods to create anMGLStyleValueobject.The
MGLStyleValueclass takes a generic parameterTthat indicates the Foundation class being wrapped by this class. Common values forTinclude:NSNumber(for Boolean values and floating-point numbers)NSValue(forCGVector,NSEdgeInsets,UIEdgeInsets, and enumerations)NSStringNSColororUIColorNSArray
Declaration
Objective-C
@interface MGLStyleValue <T> : NSObjectSwift
class MGLStyleValue
-
Declaration
Objective-C
@interface MGLLight : NSObjectSwift
class MGLLight : NSObject
Install in Dash
Styling the Map Reference